Skip to content

feat(hooks): add V4 checkpoint writer for long DeepSeek V4 sessions#5438

Open
EvangelosMoschou wants to merge 2 commits into
code-yeongyu:devfrom
EvangelosMoschou:feat/v4-checkpoint-writer
Open

feat(hooks): add V4 checkpoint writer for long DeepSeek V4 sessions#5438
EvangelosMoschou wants to merge 2 commits into
code-yeongyu:devfrom
EvangelosMoschou:feat/v4-checkpoint-writer

Conversation

@EvangelosMoschou

@EvangelosMoschou EvangelosMoschou commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Problem

DeepSeek V4 loses coherence on long sessions. MiMo Code's research showed that periodic state extraction at intervals keeps context lean and enables crash recovery.

Fix

New v4-checkpoint-writer hook (ToolGuard tier) that:

  1. Tracks V4 sessions from message.updated events
  2. Every 20 tool calls, writes a checkpoint file to .omo/checkpoints/{sessionID}.json
  3. The checkpoint contains: session ID, model ID, tool call count, last tool name, timestamp
  4. Non-V4 sessions are completely unaffected (zero overhead)

Checkpoint file format:

{
  "sessionID": "ses_abc123",
  "modelID": "deepseek/deepseek-v4-pro",
  "toolCallCount": 20,
  "lastToolName": "bash",
  "timestamp": "2026-06-19T17:30:00.000Z"
}

TDD Evidence

4 tests covering all paths:

  • V4 session at 20 tool calls -> checkpoint file written with correct data
  • V4 session at 19 tool calls -> NO checkpoint (interval not reached)
  • Non-V4 session at 20 tool calls -> NO checkpoint (V4-only)
  • V4 session at 40 tool calls -> 2nd checkpoint written (overwrites with count=40)

All existing tool-guard composition tests still pass.

Research backing

From MiMo Code's architecture (which beat Claude Code at >200-step tasks):

Files

  • packages/omo-opencode/src/hooks/v4-checkpoint-writer/hook.ts (new) -- hook implementation
  • packages/omo-opencode/src/hooks/v4-checkpoint-writer/index.ts (new) -- barrel export
  • packages/omo-opencode/src/hooks/v4-checkpoint-writer/hook.test.ts (new) -- 4 tests
  • packages/omo-opencode/src/hooks/index.ts -- barrel export added
  • packages/omo-opencode/src/plugin/hooks/create-tool-guard-hooks.ts -- hook registered
  • packages/omo-opencode/src/config/schema/hooks.ts -- hook name added to HookNameSchema

Usage

The hook is always on (can be disabled via disabled_hooks):

{
  "disabled_hooks": ["v4-checkpoint-writer"]
}

Complements PR #5403 (DeepSeek V4 Sisyphus + compaction) and PR #5437 (V4 verification gate).

Conflict note

This PR and #5437 (V4 verification gate) both modify the same 3 files: hooks.ts, hooks/index.ts, and create-tool-guard-hooks.ts. Whichever merges first, the other will need a rebase to resolve merge conflicts in those files. If you'd like me to batch-rebase one onto the other before merging, let me know.


Summary by cubic

Add a checkpoint writer hook for DeepSeek V4 that saves session state every 20 tool calls to keep long sessions coherent and enable crash recovery. Non‑V4 sessions are unaffected.

  • New Features
    • Added v4-checkpoint-writer that tracks V4 sessions from message.updated events and writes checkpoints every 20 tool calls to <workspace>/.omo/checkpoints/{sessionID}.json (or ~/.omo/checkpoints when no workspace), including session ID, model ID, tool call count, last tool, and timestamp.
    • Enabled by default; disable via disabled_hooks: ["v4-checkpoint-writer"].
    • Registered in the hook factory and schema; export added. Tests cover interval behavior (20/19/40 calls) and non‑V4 sessions.

Written for commit 205693a. Summary will update on new commits.

Review in cubic

DeepSeek V4 loses coherence on long sessions. MiMo Code's research showed
that periodic state extraction at intervals keeps context lean and enables
crash recovery. This is a simplified version: every 20 tool calls, writes
a checkpoint file with session ID, model, tool call count, and timestamp.

The hook:
- Tracks V4 sessions from message.updated events
- Every 20 tool calls, writes checkpoint to .omo/checkpoints/{sessionID}.json
- Non-V4 sessions are unaffected (zero overhead)
- Gated behind disabled_hooks as 'v4-checkpoint-writer'

TDD: 4 tests (20 calls -> checkpoint, 19 -> no checkpoint, non-V4 -> none, 40 -> 2nd checkpoint).
All existing tool-guard composition tests still pass.
@github-actions github-actions Bot added the opencode OpenCode edition: packages/omo-opencode label Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

opencode OpenCode edition: packages/omo-opencode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant